import { createSlice, PayloadAction } from '@reduxjs/toolkit'

// Define a type for the slice state
interface UserState {
  username: string;
  password: string;
}

// Define the initial state using that type
const initialState: UserState = {
  username: 'redux用户名',
  password: 'redux密码'
}

export const counterSlice = createSlice({
  name: 'counter',
  initialState,
  reducers: {
    setUsername:(state, action: PayloadAction<string>)=> {
      state.username = action.payload
    }
  },
})

// Action creators are generated for each case reducer function
export const { setUsername } = counterSlice.actions

export default counterSlice.reducer